#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define debug(x) cerr<<#x<<':'<<x<<endl
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const int N=2e5+5;
int n,m;
struct node{
    int y,w;
};
vector<node> G[N];
int fa[N],dep[N],siz[N],son[N];
void dfs1(int x,int faa){
    fa[x]=faa,dep[x]=dep[faa]+1,siz[x]=1;
    for(auto y:G[x]){
        if(y.y==faa) continue;
        dfs1(y.y,x);
        siz[x]+=siz[y.y];
        if(siz[y.y]>siz[son[x]]) son[x]=y.y;
    }
}
int idx,dfn[N],top[N],num[N];
void dfs2(int x,int tp){
    dfn[x]=++idx,top[x]=tp;
    if(son[x]) dfs2(son[x],tp);
    for(auto y:G[x]){
        if(y.y==fa[x]) continue;
        num[y.y]=y.w;
        if(y.y==son[x]) continue;
        dfs2(y.y,y.y);
    }
}
int lca(int x,int y){
    while(top[x]^top[y]){
        if(dep[top[x]]<dep[top[y]]) swap(x,y);
        x=fa[top[x]];
    }
    if(dfn[x]>dfn[y]) swap(x,y);
    return x;
}
int a[N],sum[N];
void init(){
    for(int i=1;i<=n;i++) a[dfn[i]]=num[i];
    for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
}
int ask(int x,int y){
    int res=0;
    while(top[x]^top[y]){
        if(dep[top[x]]<dep[top[y]]) swap(x,y);
        res+=sum[dfn[top[x]]]-sum[dfn[x]-1];
        x=fa[top[x]];
    }
    if(dfn[x]>dfn[y]) swap(x,y);
    res+=sum[dfn[y]]-sum[dfn[x]-1]-a[dfn[x]];
    return res;
}
struct sgt{
    int mx,pos1;
    int mi,pos2;
}tree[N<<2];
#define ls (p<<1)
#define rs (p<<1|1)
sgt merge(sgt x,sgt y){
    sgt z;
    if(x.mx>y.mx) z.mx=x.mx,z.pos1=x.pos1;
    else z.mx=y.mx,z.pos1=y.pos1;
    if(x.mi<y.mi) z.mi=x.mi,z.pos2=x.pos2;
    else z.mi=y.mi,z.pos2=y.pos2;
    return z;
}
void build(int p,int l,int r){
    if(l==r){
        tree[p]=(sgt){dfn[l],l,dfn[l],l};
        return;
    }
    int mid=(l+r)>>1;
    build(ls,l,mid);
    build(rs,mid+1,r);
    tree[p]=merge(tree[ls],tree[rs]);
}
sgt query(int p,int l,int r,int ql,int qr){
    if(ql<=l&&r<=qr) return tree[p];
    int mid=(l+r)>>1;
    if(qr<=mid) return query(ls,l,mid,ql,qr);
    else if(ql>mid) return query(rs,mid+1,r,ql,qr);
    else return merge(query(ls,l,mid,ql,qr),query(rs,mid+1,r,ql,qr));
}
void makeroot(int s){
    for(int i=1;i<=n;i++) son[i]=fa[i]=siz[i]=dep[i]=num[i]=sum[i]=a[i]=dfn[i]=top[i]=0;
    idx=0;
    dfs1(s,0);
    dfs2(s,s);
    init();
    build(1,1,n);
}
signed main(){
    freopen("memory.in","r",stdin);
    freopen("memory.out","w",stdout);
    IOS;
    cin>>n>>m;
    for(int i=1,u,v,w;i<n;i++){
        cin>>u>>v>>w;
        G[u].push_back({v,w});
        G[v].push_back({u,w});
    }
    dfs1(1,0);
    dfs2(1,1);
    init();
    build(1,1,n);
    int root=1;
    for(int i=1,p,l,r,lastans=0;i<=m;i++){
        cin>>p>>l>>r;
        p^=lastans,l^=lastans,r^=lastans;
        if(p!=root) makeroot(p),root=p;
        sgt res=query(1,1,n,l,r);
        lastans=ask(p,lca(res.pos1,res.pos2));
        cout<<lastans<<endl;
    }
    return 0;
}